/**
 * 签到
 */
$(function () {
    $("#page").load(URI + "/rbac/html/page.html");
});

//查询所有数据
function findAll() {
    //trim()去掉两边的空格
    let data = {
        username: $("#username").val(),
        sno: $("#sno").val(),
        nickName: $("#nickName").val(),
        phone: $("#phone").val(),
        pageNum: $("#pageNum").val(),
        pageSize: $("#pageSize").val()
    };
    let result = myAjax("/api/rb/user/getStudent", data, "post");
    // console.log(resultList);
    // let  result = adminLogin(resultList);
    // 总条数
    if (result) {
        $("#totalCount").html(result.data.count);
        setData(result.data.pageInfo.list);
    }
}

//遍历查询到的数据
function setData(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        html += " <tr >\n" +
            "            <td>" + data[i].id + "</td>\n" +
            "            <td title='" + data[i].nickName + "'>" + clearNull(data[i].nickName) + "</td>\n" +
            // "            <td title='" + data[i].username + "'>" + clearNull(data[i].username) + "</td>\n" +
            "            <td title='" + data[i].icon + "'><img src='" + clearNull(URI + IMG + data[i].icon) + "' style='width: 30px; height: 30px;' ></td>\n" +
            "            <td title='" + data[i].sex + "'>" + clearNull(data[i].sex) + "</td>\n" +
            // "            <td title='" + data[i].age + "'>" + clearNull(data[i].age) + "</td>\n" +
            "            <td title='" + data[i].phone + "'>" + clearNull(data[i].phone) + "</td>\n" +
            "            <td title='" + data[i].email + "'>" + clearNull(data[i].email) + "</td>\n" +
            "            <td title='" + data[i].sno + "'>" + clearNull(data[i].sno) + "</td>\n" +
            "            <td title='" + data[i].className + "'>" + clearNull(data[i].className) + "</td>\n" +
            "            <td title=''>" +
            "               <input type=\"radio\" name=\"status\" value=\"已到\">已到\n" +
            "               <input type=\"radio\" name=\"status\" value=\"迟到\">迟到\n" +
            "               <input type=\"radio\" name=\"status\" value=\"请假\">请假\n" +
            "               <input type=\"radio\" name=\"status\" value=\"旷课\">旷课\n" +
            "            </td>\n" +
            "            <td title=''>" +
            "                  <input type=\"date\" id='signLateTime' class=\"layui-input\">\n" +
            "            </td>\n" +
            "            <td class=\"td-manage\" style='text-align: center;'>\n" +
            "                  <div id='sign' style='background-color: #00FF00;width: 40px;height: 40px; border-radius: 50%;display: flex;align-items:center ;justify-content: center;font-size: larger;'>" +
            "                      <i class=\"layui-icon layui-icon-close\" id='icon' onclick=\"sign(" + data[i].id + ")\" style='color: blue;font-size: 18px; font-weight: bolder;'></i>\n"+
            "                  </div>  "+
            "            </td>\n" +
            "          </tr>";
    }
    $("#tbody").html(html);
}

/***
 * 清除数据中的undefined和null将其置换为空，不显示
 */

function clearNull(value) {
    return value === "null" || value === undefined ? "" : value;
}


/***
 * 删除功能
 */
function del(id) {
    let result = myAjax("/api/rb/user/del", {id: id}, "delete");
    if (result.code === 200) {
        //删除成功，就重新查询数据
        alert("删除成功(== ^^ ==)!");
        findAll();
    } else {
        alert("删除失败(╥╯^╰╥)！")
    }
}

/**
 * 签到
 */
// function sign(id) {
//     sessionStorage.setItem("newUserId",id);
//     x_admin_show('编辑', URI + '/rbac/html/student/sign-update.html', 600, 600);
// }



function sign(id) {
    let data={
        userId:id,
        status:$("input:radio[name='status']:checked").val(),
        lateTime:$("#signLateTime").val()
    };
    console.log(data,"1111111111");
    let result = myAjax("/api/stu/student/sign", data, "post");

    if (result.data === 1) {
        //签到成功
        alert(result.message);
        $("#icon").attr("class","layui-icon layui-icon-close");
        x_admin_father_reload();
    } else {
        alert(result.message);
    }
}

